package homework;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class CharacterTotal {
	
	public int getNumAmount(String filePath) throws FileNotFoundException{        //统计数字
		int count=0;
		String regNum="[0-9]";
		String string=new Scanner(new FileInputStream(new File(filePath))).next();
		Pattern pNum=Pattern.compile(regNum);
		Matcher matcherNum=pNum.matcher(string);
		while (matcherNum.find()) {
			count++;	
		}
		return count;
	}
	public int getCharAmount(String filePath)throws FileNotFoundException{      //找字符
		int count=0;
		String regChar="[a-zA-Z]";
		String string=new Scanner(new FileInputStream(new File(filePath))).next();
		Pattern pChar=Pattern.compile(regChar);
		Matcher matcherChar=pChar.matcher(string);
		while (matcherChar.find()) {
			count++;	
		}
		return count;
		
	}
	
	public int getChineseAmount(String filePath)throws FileNotFoundException{    //统计中文字符
		int count=0;
		String regChinese="[u4e00-u9fa5]";
		String string=new Scanner(new FileInputStream(new File(filePath))).next();
		Pattern pChinese=Pattern.compile(regChinese);
		Matcher matcherChinese=pChinese.matcher(string);
		while (matcherChinese.find()) {
			count++;	
		}
		return count;
		
	}
	
	public int getPunctuationAmount(String filePath)throws FileNotFoundException{   //统计标点符号
		int count=0;
		String regPunctuation="[\\pP‘’“”]";
		String string=new Scanner(new FileInputStream(new File(filePath))).next();
		Pattern pPunctuation=Pattern.compile(regPunctuation);
		Matcher matcherPunctuation=pPunctuation.matcher(string);
		while (matcherPunctuation.find()) {
			count++;	
		}
		return count;
		
	}
//	public static void main(String[] args) {
//		CharacterTotal cTotal=new CharacterTotal();
//		try{
//			int a = cTotal.getNumAmount("abc.txt");
//			System.out.println(a);
//		}catch(FileNotFoundException e){
//			e.printStackTrace();
//		}
		
		
		
	
	
}
